<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="icon iconfont icon-jifen"></i> 旅游列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                线路标题：
                <el-input v-model="title" placeholder="请输入新闻标题" class="handle-input"></el-input>
                <el-button type="primary" icon="search" @click="search">查询</el-button>
                <router-link to="/tour/add">
                    <el-button type="primary" icon="search" >发布线路</el-button>
                </router-link>
            </div>
            <el-table :data="tableData" border style="width: 100%" >
                <el-table-column prop="id" label="ID" width="80" align="center">
                </el-table-column>
                <el-table-column prop="title" label="标题" >
                </el-table-column>
                <el-table-column prop="create_time" label="发布日期" width="120">
                </el-table-column>
                <el-table-column prop="member_price" label="优惠价" width="140">
                </el-table-column>
                <el-table-column prop="normal_price" label="原价" width="140">
                </el-table-column>
                <el-table-column label="操作" width="140" align="center">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleSelect(scope.$index, scope.row)">查看</el-button>
                        <el-button size="small" type="text" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="small" type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination" v-show="totalPages>10">
                <el-pagination @current-change="handleCurrentChange" layout="prev, pager, next" :total="totalPages">
                </el-pagination>
            </div>
        </div>
        <!-- 删除提示框 -->
        <el-dialog title="提示" :visible.sync="delVisible" width="300px" center>
            <div class="del-dialog-cnt">删除不可恢复，是否确定删除？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="delVisible = false">取 消</el-button>
                <el-button type="primary" @click="deleteRow">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name:"member",
    data () {
        return {
            fit:false,
            pageIndex:1,//当前页码
            pageSize:10,//每页10条
            totalPages:1,//默认的总条数
            title:'',// 新闻标题
            tableData:[],//表格数据
            delVisible:false, //是否显示查看详情弹出层
            delIndex:0,
            delId:0

        }
    },
    created() {
        this.getMemberData();
    },
    watch :{
        countTime: function(val){

        }
    },
    methods: {
        //获取tabs数据
        getMemberData (){
            const querystring = require('querystring');
            const param ={
                title:this.title,
                pageIndex:this.pageIndex,
                pageSize:this.pageSize
            }
            this.$axios.post('/manage/tour-line/query',querystring.stringify(param)).then(response=>{
                //console.log(response);
                if(response.data.code==200){
                    response.data.data.currData.some(item => {
                        item.create_time = item.create_time.slice(0,10);
                    })
                    this.tableData = response.data.data.currData;//赋值 table 列表数据
                    this.totalPages = response.data.data.totalPages;//更新分页总条数
                }else{
                    this.$notify.error({
                        title: '获取新闻列表失败',
                        duration:2000,
                        message: '失败原因：'+response.data.msg
                    });
                }
                
            }).catch(error=>{
                console.log(error); 
            });
        },
        // 分页导航
        handleCurrentChange (val){
            // this.cur_page = val;
            //     this.getData();
        },
        //查询
        search (){
            this.getMemberData();
        },
        //编辑
        handleEdit (index,row){
            if(row.id && row.id>0){
                this.$router.push({path:"/tour/edit",query:{id:row.id}});
            }
        },
        //删除
        handleDelete (index,row){
            if(row.id && row.id>0){
                this.delVisible = true;
                this.delIndex = index;//当前要删除的下标
                this.delId = row.id;// 当前选中ID
            }
        },
        deleteRow (){
            //console.log("触发了确定");
            if(this.delId>0){
                const querystring = require('querystring');
                const param ={
                    id:this.delId
                }
                this.$axios.post('/manage/tour-line/delete',querystring.stringify(param)).then(response=>{
                    //console.log(response);
                    if(response.data.code==200){
                        this.tableData.splice(this.delIndex, 1);
                        this.$message.success('删除成功');
                        this.delVisible = false;
                    }else{
                        this.$notify.error({
                            title: '删除失败',
                            duration:2000,
                            message: '失败原因：'+response.data.msg
                        });
                    }
                    
                }).catch(error=>{
                    console.log(error); 
                });
            }
        },
        //查询新闻详情，跳转到详情页面
        handleSelect (index, row){
            if(row.id && row.id>0){
                this.$router.push({path:"/tour/select/"+row.id});
            }
            
        }  
            
    }
}
</script>
<style lang="stylus" scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
        margin-right :30px;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
</style>


